#include "llvm/Module.h"
#include <iostream>
#include "llvm/IRBuilder.h"
#include "llvm/Value.h"
#include <typeinfo>
#include "Control.h"

using namespace llvm;

int main (int argc, char *argv[])
{
	LLVMContext &Context = getGlobalContext();
	Module *TheModule = new Module("Module",Context);
	IRBuilder<> Builder(Context);
	std::vector<Type*> Pointers(2, Type::getInt32PtrTy(Context));
	FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), Pointers, false);
	Function *F = Function::Create(FT, Function::ExternalLinkage, "superCoolFunction", TheModule);
	
	std::vector<std::string> names;
	std::vector<Value*> values;
	names.push_back("Alan");
	names.push_back("Neil");
	unsigned i = 0;
	for (Function::arg_iterator AI = F->arg_begin(); i != 2; ++AI, ++i) {
		AI->setName(names.at(i));
		values.push_back(AI);
	}
	
	
	BasicBlock *bbq = BasicBlock::Create(Context, "ininurfunction", F);
	Builder.SetInsertPoint(bbq);
	Value* meh = Builder.CreateLoad(values.at(0), "Bless");
	Value* meh2 = Builder.CreateLoad(values.at(1), "MOOOOOO");
	IRBuilder<> Builder2(Context); 
	Builder2.CreateAdd(meh, meh2, "mooblessing");
	
	TheModule->dump();
	
	std::cout << typeid(Control).name() << std::endl;
}
